package com.shopx.config.controller;

import com.shopx.base.anno.RepearSubmitChkAnno;
import com.shopx.base.anno.ShopxParamAnno;
import com.shopx.base.dto.Result;
import com.shopx.base.utils.ResultUtil;
import com.shopx.cmm.DTO.PageDTO;
import com.shopx.config.bean.SysConfig;
import com.shopx.config.bean.SysDict;
import com.shopx.config.model.SysConfigModel;
import com.shopx.config.service.ISysConfigService;
import com.shopx.core.common.CommonConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author lituo
 * @className: SysConfigController
 * @description: 配置
 * @date 2021/12/5 12:04 PM
 */
@RestController
@Slf4j
@RequestMapping(value = "/sysConfig")
public class SysConfigController {
  @Autowired
  private ISysConfigService sysConfigService;

  /**
   * 查询分页记录
   *
   * @param sysConfig
   * @return
   * @author lituo
   * @date 11:42 AM 2021/12/5
   */
  @PostMapping("/queryPageList")
  public Result<SysConfigModel> queryPageList(@RequestBody SysConfigModel sysConfig) {
    PageDTO<SysConfigModel> pageDTO = sysConfigService.getListPage(sysConfig);
    return ResultUtil.ok(pageDTO);
  }

  /**
   * 新增记录
   *
   * @param sysConfig
   * @return
   * @author lituo
   * @date 11:42 AM 2021/12/5
   */
  @PostMapping("/insertOne")
  @RepearSubmitChkAnno(lockTime = CommonConstant.REQ_TM)
  @ShopxParamAnno
public Result<Integer> insertOne(@RequestBody SysConfig sysConfig) {
    int result = sysConfigService.insertSelective(sysConfig);
    return ResultUtil.ok(result);
  }

  /**
   * 修改记录
   *
   * @param sysConfig
   * @return
   * @author lituo
   * @date 11:42 AM 2021/12/5
   */
  @PostMapping("/updateOne")
  @RepearSubmitChkAnno(lockTime = CommonConstant.REQ_TM)
  @ShopxParamAnno
public Result<Integer> updateOne(@RequestBody SysConfig sysConfig) {
    int result = sysConfigService.updateByPrimaryKeySelective(sysConfig);
    return ResultUtil.ok(result);
  }

  /**
   * 查询明细记录
   *
   * @param sysConfig
   * @return
   * @author lituo
   * @date 11:42 AM 2021/12/5
   */
  @PostMapping(value = "/queryOneByPrimaryKey")
  public Result<SysConfigModel> queryOneByPrimaryKey(@RequestBody SysConfig sysConfig) {
    SysConfigModel result = sysConfigService.selectByPrimaryKey(sysConfig);
    return ResultUtil.ok(result);
  }

  /**
   * 删除单条记录
   *
   * @param sysConfig
   * @return
   * @author lituo
   * @date 11:42 AM 2021/12/5
   */
  @PostMapping(value = "/deleteChecked")
  @RepearSubmitChkAnno(lockTime = CommonConstant.REQ_TM)
  public Result<SysConfigModel> deleteChecked(@RequestBody SysConfig sysConfig) {
    int result = sysConfigService.deleteByPrimaryKey(sysConfig);
    return ResultUtil.ok(result);
  }

  @PostMapping(value = "/deleteBatch")
  @RepearSubmitChkAnno(lockTime = CommonConstant.REQ_TM)
  public Result<?> deleteBatch(@RequestBody List<SysConfig> list) {
    sysConfigService.deleteBatch(list);
    return ResultUtil.ok(true);
  }

}
